import { request } from '@/utils/request.js'; //导入封装好的js文件

// 最新动态
export const getCommunityApi = (data) => {
  return request({
    url: '/content/news',
    method: 'get',
    data
  });
};

// 发布动态
export const postCommunityApi = (data) => {
  return request({
    url: '/content/post',
    method: 'post',
    data,
    header: {
      'Content-Type': 'application/x-www-form-urlencoded' // 关键头信息
    }
  });
};

// 点赞
export const likeApi = (id) => {
  return request({
    url: `/content/like/${id}`,
    method: 'post'
  });
};

// 取消点赞
export const cancelLikeApi = (id) => {
  return request({
    url: `/content/unlike/${id}`,
    method: 'post'
  });
};

// 评论
export const commentApi = (data) => {
  return request({
    url: `/content/comment/${data.id}`,
    method: 'post',
    data,
    header: {
      'Content-Type': 'application/x-www-form-urlencoded' // 关键头信息
    }
  });
};

// 评论
export const getCommentApi = (id) => {
  return request({
    url: `/content/comments/list/${id}`,
    method: 'get'
  });
};
// 关注
export const followAuthApi = (userid) => {
  return request({
    url: `/content/follow/${userid}`,
    method: 'post'
  });
};

// 取消关注
export const cancelFollowAuthApi = (userid) => {
  return request({
    url: `/content/unfollow/${userid}`,
    method: 'post'
  });
};
// 是否关注
export const isFollowAuthApi = (userid) => {
  return request({
    url: `/content/isFollowing/${userid}`,
    method: 'get'
  });
};
// 内容详情
export const getContentApi = (id) => {
  return request({
    url: `/content/${id}`,
    method: 'get'
  });
};
// 关注的内容
export const getFollowContentApi = (id) => {
  return request({
    url: `/content/following/contents`,
    method: 'get'
  });
};

// 点赞评论
export const commentLikeApi = (commentId) => {
  return request({
    url: `/content/comment/like/${commentId}`,
    method: 'post'
  });
};
// 取消点赞评论
export const commentUnlikeApi = (commentId) => {
  return request({
    url: `/content/comment/unlike/${commentId}`,
    method: 'post'
  });
};
// 社区主页
export const commentIndexApi = (data) => {
  return request({
    url: `/content/index/info`,
    method: 'get',
    data
  });
};
// 用户发帖列表
export const userPostApi = (data) => {
  return request({
    url: `/content/index/posts`,
    method: 'get',
    data
  });
};
// 转发
export const sharePostApi = (data) => {
  return request({
    url: `/content/share/${id}`,
    method: 'post',
    data
  });
};
// 打赏
export const postRewardApi = (data) => {
  return request({
    url: `/points/reward`,
    method: 'post',
    data,
    header: {
      'Content-Type': 'application/x-www-form-urlencoded' // 关键头信息
    }
  });
};
